<?php
namespace app\laytemp;

class Layers{
    private $layHtml = [];
    protected $layBody = [];
    private $title = '设置标题';
    public function __construct(){
        $this->registTemp();
        $this->head();
    }
    //注册模板顺序
    private function registTemp(){
        $this->layHtml=[
            'head'=>'',
            'body'=> $this->layBody,
            'foot'=>''
        ];
    }
    private function head(){
        $assigin_arr = [
            'title' => $this->title
        ];
        $this->layHtml['head'] = view('laytemp@common/head',$assigin_arr)->getContent();
        return $this;
    }

    //设置标题
    public function setTitle($title=''){
        $this->title = $title;
        return $this->head();
    }

    //渲染页面
    public function view(){
        $this->layHtml['foot']= view('laytemp@common/foot')->getContent();
        $html = $this->layHtml['head'];
        foreach ($this->layBody as $ht){
            $html.=$ht;
        }
        $html.= $this->layHtml['foot'];
        return $html;
    }
}
